import { createHashRouter } from 'react-router-dom'
import HomePage from '@renderer/pages/Home'
import ConfigPage from '@renderer/pages/Config'
import ContentListPage from '@renderer/pages/Config/ContentList'
const router = createHashRouter([
  {
    path: '/',
    element: <HomePage />
  },
  {
    path: '/config',
    element: <ConfigPage />,
    loader: () => {
      return window.api.sql('select * from categories order by id desc ', 'findAll')
    },
    children: [
      {
        path: 'contentList/:cid?',
        element: <ContentListPage />,
        loader: ({ params }) => {
          const { cid } = params
          let sql = `select * from contents `

          if (cid !== undefined) {
            sql += `where category_id=${cid}`
          }

          sql += ' order by id desc'
          return window.api.sql(sql, 'findAll')
        }
      }
    ]
  }
])
export default router
